package com.hmy.pig.controller;

import com.hmy.pig.domain.HmyPig;
import com.hmy.pig.domain.HmyPigBreed;
import com.hmy.pig.service.PigBreedService;
import com.hmy.pig.service.PigService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ruoyi.common.core.utils.PageUtils.startPage;

/**
 * @author zhl
 * @descript 描述
 * @date 2024-01-29
 */

@RestController
@RequestMapping("/pigBreed")
public class HmyPigBreedController extends BaseController {
    @Autowired
    private PigBreedService pigBreedService;

    /**
     * 查询进货信息列表
     *
     * @param pigCode      参数一：母猪耳号
     * @param pigBreedType  参数二：配种方式
     * @param pigBreedManager  参数二：配种负责人
     * @param dateStart 参数三：进货开始时间
     * @param dateEnd   参数四：进货结束时间
     * @return 返回查询列表
     */
    @RequiresPermissions("hmy:pigBreed:list")
    @GetMapping("/list")
    public TableDataInfo list(String pigCode ,
                              Integer pigBreedType,
                              String pigBreedManager,
                              String dateStart,
                              String dateEnd)
    {
        startPage();
        List<HmyPigBreed> list = pigBreedService.selectPigBreedList(pigCode,pigBreedType,pigBreedManager,dateStart,dateEnd);
        return getDataTable(list);
    }
    /**
     * @param hmyPigBreed
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @author ZHL
     * @date 2024/1/29 19:10
     * @description  新增猪只配种记录
     */
    @RequiresPermissions("hmy:pigBreed:add")
    @Log(title = "猪只配种记录管理", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add( @RequestBody HmyPigBreed hmyPigBreed)
    {
        System.out.println("hmypig"+hmyPigBreed);
        return toAjax(pigBreedService.insertPigBreed(hmyPigBreed));
    }
    /**
     * 根据pigBreedId获取单个配种记录信息
     *
     * @param pigBreedId
     * @return
     */
    @RequiresPermissions("hmy:pigBreed:query")
    @GetMapping("getInfo/{pigBreedId}")
    public AjaxResult selectPigBreedById(@PathVariable Long pigBreedId) {
        return AjaxResult.success(pigBreedService.selectPigBreedByPigBreedId(pigBreedId));
    }
    /**
     * 根据pigBreedId修改配种记录信息
     *
     * @param hmyPigBreed
     * @return
     */
    @PostMapping("update")
    @Log(title = "猪只配种记录管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("hmy:pigBreed:update")
    public AjaxResult updatepigBreed(@RequestBody HmyPigBreed hmyPigBreed) {
        return toAjax(pigBreedService.updatePigBreed(hmyPigBreed));

    }

    /**
     * 根据ID删除配种记录信息
     *
     * @param pigBreedIds
     * @return
     */
    @DeleteMapping("del/{pigBreedIds}")
    @RequiresPermissions("hmy:pigBreed:del")
    public AjaxResult delPigBreedByPigBreedId(@PathVariable Long[] pigBreedIds) {
        return toAjax(pigBreedService.deletePigBreedByPigBreedIds(pigBreedIds));
    }

    @GetMapping("findAllStaffName")
    public AjaxResult findAllStaffName(){
        return AjaxResult.success(pigBreedService.findAllStaffName());
    }

}
